home *** CD-ROM | disk | FTP | other *** search
/ Nebula 1 / Nebula One.iso / Utilities / Converters / Convert_PICT / Source / CommentedPSCode / RCS / Polygons,v < prev    next >
Encoding:
Text File  |  1995-06-12  |  9.8 KB  |  479 lines

  1. head     1.8;
  2. branch   ;
  3. access   ;
  4. symbols  beta10:1.7;
  5. locks    death:1.8;
  6. comment  @# @;
  7.  
  8.  
  9. 1.8
  10. date     93.04.04.23.31.00;  author death;  state Exp;
  11. branches ;
  12. next     1.7;
  13.  
  14. 1.7
  15. date     93.01.09.21.07.37;  author death;  state Exp;
  16. branches ;
  17. next     1.6;
  18.  
  19. 1.6
  20. date     93.01.01.11.51.43;  author death;  state Exp;
  21. branches ;
  22. next     1.5;
  23.  
  24. 1.5
  25. date     92.12.31.15.35.27;  author death;  state Exp;
  26. branches ;
  27. next     1.4;
  28.  
  29. 1.4
  30. date     92.12.05.23.07.38;  author death;  state Exp;
  31. branches ;
  32. next     1.3;
  33.  
  34. 1.3
  35. date     92.12.03.18.02.11;  author death;  state Exp;
  36. branches ;
  37. next     1.2;
  38.  
  39. 1.2
  40. date     92.11.27.19.38.17;  author death;  state Exp;
  41. branches ;
  42. next     1.1;
  43.  
  44. 1.1
  45. date     92.11.08.09.29.02;  author death;  state Exp;
  46. branches ;
  47. next     ;
  48.  
  49.  
  50. desc
  51. @@
  52.  
  53.  
  54. 1.8
  55. log
  56. @Sun Apr  4 23:31:00 PDT 1993
  57. @
  58. text
  59. @%BEGIN Polygons
  60.  
  61. %%%%%%%%%%%%%
  62. %    Notes:
  63. %        PICTline is defined in the common file.  As is penWidth and penHeight
  64. %%%%%%%%%%%%%
  65.  
  66. %%%%%%%%%%%%%
  67. %    Name:    polyPath
  68. %    Syntax:    [x1 y1] ... [xN yN] N rect polyPath -
  69. %    About:    Builds a path corresponding to the polygon passed as set of x,y coords 
  70. %            (each coord in an array), count of these points, and bounding rectangle.
  71. %            Notes: This changes the clip path.  Call inside a gsave/restore.  We deliberately
  72. %            end with an open path, since mac polygons aren't always closed(?)
  73. %%%%%%%%%%%%%
  74. /polyPath
  75. {
  76.     /right    exch def
  77.     /bottom    exch def
  78.     /left    exch def
  79.     /top    exch def
  80.     /points exch def
  81.     %
  82.     %    Build the bounding/clipping rect, and intersect it with the current clip
  83.     %
  84.     newpath
  85.         left top moveto
  86.         right top lineto
  87.         right bottom lineto
  88.         left bottom lineto
  89.     closepath
  90.     clip
  91.     %
  92.     %    move to the first point on the stack, then, connect lines to each of the others
  93.     %
  94.     newpath
  95.         /ptarray exch def
  96.         ptarray 0 get
  97.         ptarray 1 get
  98.         moveto
  99.         points 1 sub
  100.         {
  101.             /ptarray exch def
  102.             ptarray 0 get
  103.             ptarray 1 get
  104.             lineto
  105.         }
  106.         repeat    % for (points-1) times
  107. } def
  108.  
  109. %%%%%%%%%%%%%
  110. %    Name:    framePoly        [0070]
  111. %    Syntax:    [x1 y1] ... [xN yN] N rect framePoly -
  112. %    About:    For each coordinate pair of the polygon, call PICTline so it is drawn with
  113. %            the right thickness and overhand.
  114. %            Note: framed polys don't seem affected by the bounding rect.
  115. %%%%%%%%%%%%%
  116. /framePoly
  117. {
  118.     /right    exch def
  119.     /bottom    exch def
  120.     /left    exch def
  121.     /top    exch def
  122.     /points exch def
  123.     gsave
  124.         penPattern usePattern
  125.         %
  126.         %    Retrieve the first point off the stack, and store.
  127.         %
  128.         /ptarray exch def
  129.         /lastX ptarray 0 get def
  130.         /lastY ptarray 1 get def
  131.         points 1 sub
  132.         {
  133.             %
  134.             %    Fetch next point, push last pt, and then define lastX and Y as the new
  135.             %    point.  Call PICTline with pushed pt. and 'last' pt.
  136.             %
  137.             /ptarray exch def
  138.             lastX lastY 
  139.             /lastX ptarray 0 get def
  140.             /lastY ptarray 1 get def
  141.             lastX lastY PICTline
  142.         }
  143.         repeat    % for (points-1) times
  144.     grestore
  145. }
  146. def
  147.  
  148. %%%%%%%%%%%%%
  149. %    Name:    paintPoly        [0071]
  150. %    Syntax:    [x1 y1] ... [xN yN] N rect paintPoly -
  151. %    About:    Given polygon data, build a path, fill with pen pattern
  152. %%%%%%%%%%%%%
  153. /paintPoly
  154. {
  155.     gsave
  156.         penPattern usePattern
  157.         polyPath
  158.         fill
  159.     grestore
  160. }
  161. def
  162.  
  163. %%%%%%%%%%%%%
  164. %    Name:    erasePoly        [0072]
  165. %    Syntax:    [x1 y1] ... [xN yN] N rect erasePoly -
  166. %    About:    Given polygon data, build a path, fill with background pattern
  167. %%%%%%%%%%%%%
  168. /erasePoly
  169. {
  170.     gsave
  171.         backPattern usePattern
  172.         polyPath
  173.         fill
  174.     grestore
  175. }
  176. def
  177.  
  178. %%%%%%%%%%%%%
  179. %    Name:    invertPoly        [0073]
  180. %    Syntax:    [x1 y1] ... [xN yN] N rect invertPoly -
  181. %    About:    Call polyPath to consume arguments.  But don't invert (dunno how)
  182. %%%%%%%%%%%%%
  183. /invertPoly
  184. {
  185.     gsave
  186.         polyPath
  187.     grestore
  188. }
  189. def
  190.  
  191. %%%%%%%%%%%%%
  192. %    Name:    fillPoly        [0074]
  193. %    Syntax:    [x1 y1] ... [xN yN] N rect fillPoly -
  194. %    About:    Passed a polygon, this builds the path, and fills it
  195. %%%%%%%%%%%%%
  196. /fillPoly
  197. {
  198.     gsave
  199.         fillPattern usePattern
  200.         polyPath
  201.         fill
  202.     grestore
  203. } def
  204.  
  205. %%%%%%%%%%%%%
  206. %    Name:    frameSamePoly        [0078]
  207. %    Syntax:    - frameSamePoly -
  208. %    About:    This is not implemented by Apple, so we do nothing here
  209. %%%%%%%%%%%%%
  210. /frameSamePoly
  211.     { }
  212. def
  213.  
  214. %%%%%%%%%%%%%
  215. %    Name:    paintSamePoly        [0079]
  216. %    Syntax:    - paintSamePoly -
  217. %    About:    This is not implemented by Apple, so we do nothing here
  218. %%%%%%%%%%%%%
  219. /paintSamePoly
  220.     { }
  221. def
  222.  
  223. %%%%%%%%%%%%%
  224. %    Name:    eraseSamePoly        [007A]
  225. %    Syntax:    - eraseSamePoly -
  226. %    About:    This is not implemented by Apple, so we do nothing here
  227. %%%%%%%%%%%%%
  228. /eraseSamePoly
  229.     { }
  230. def
  231.  
  232. %%%%%%%%%%%%%
  233. %    Name:    invertSamePoly        [007B]
  234. %    Syntax:    - invertSamePoly -
  235. %    About:    This is not implemented by Apple, so we do nothing here
  236. %%%%%%%%%%%%%
  237. /invertSamePoly
  238.     { }
  239. def
  240.  
  241. %%%%%%%%%%%%%
  242. %    Name:    fillSamePoly            [007C]
  243. %    Syntax:    - fillSamePoly -
  244. %    About:    This is not implemented by Apple, so we do nothing here
  245. %%%%%%%%%%%%%
  246. /fillSamePoly
  247.     { }
  248. def
  249.  
  250. %END Polygons
  251. @
  252.  
  253.  
  254. 1.7
  255. log
  256. @Sat Jan  9 21:07:36 PST 1993
  257. @
  258. text
  259. @@
  260.  
  261.  
  262. 1.6
  263. log
  264. @Fri Jan  1 11:51:43 PST 1993
  265. @
  266. text
  267. @d28 3
  268. a30 3
  269.         right 1 add top lineto
  270.         right 1 add bottom 1 add lineto
  271.         left bottom 1 add lineto
  272. @
  273.  
  274.  
  275. 1.5
  276. log
  277. @Thu Dec 31 15:35:27 PST 1992
  278. @
  279. text
  280. @@
  281.  
  282.  
  283. 1.4
  284. log
  285. @Sat Dec  5 23:07:37 PST 1992
  286. @
  287. text
  288. @d3 4
  289. a6 3
  290. %
  291. %    PICTline is defined in the common file.  As is penWidth and penHeight
  292. %
  293. d8 8
  294. a15 20
  295. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  296. %    utility:    polyPath
  297. %    Syntax:    [x y] ... [x y] n rect polyPath -
  298. %    Description:
  299. %        Takes a polygon from the path, and builds a corresponding path.
  300. %        What is a polygon?  Well, it is just a series of line segments (not necessarily
  301. %        'closed').  It is stored on the stack as: a bounding rectangle (which we ignore),
  302. %        the number of poins making up the polygon, and then the points themselves stored
  303. %        as x,y pairs.  Each pair is stored as an array (this is mainly done to make the PS code
  304. %        somewhat legible to the human eye).  Loop for the number of points there are,
  305. %        pull out the coords, and build a path with them.
  306. %    Warnings (bugs?):
  307. %        This ends with an open path.  It is conceivable that we should be watching if
  308. %        the last point is the same as the first, and close the path if so.  I dunno for
  309. %        what PICT does on the Mac...
  310. %        This routine CHANGES THE CLIP PATH.  Beware of this.  Best to call this inside
  311. %        a gsave/grestore pair.
  312. %        A polygon, even when filled has the same edge boundry nature that a pict line does:
  313. %        it decends down and to the right one pixel.  This does NOT replicate that
  314. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  315. a22 1
  316.  
  317. d24 1
  318. a24 1
  319.     %    First, build a rectangle that bounds the polygons clipping area, and intersect it with the current clip
  320. a32 1
  321.  
  322. d51 7
  323. a57 12
  324.  
  325.  
  326. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  327. %    Opcode:    0070
  328. %    Name:    framePoly
  329. %    Syntax:    [x y] ... [x y] n rect framePoly -
  330. %    Description:
  331. %        Given a polygon, this walks through the array of points making up
  332. %        the polygon.  For every pair (save the first and last), this calls
  333. %        our common routine PICTline to draw the line properly.
  334. %        Note that framed polygons donn't seem affected by the bounding/clipping rectangle
  335. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  336. d76 2
  337. a77 4
  338.             %    Fetch the next point, push the previous one on the stack as the first
  339.             %    pair of arguments to PICTline, get the coords out of the retrieved point,
  340.             %    and pass to PICTline (these will be used again as the first args next
  341.             %    time through this loop)
  342. d90 5
  343. a94 8
  344.  
  345. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  346. %    Opcode:    0071
  347. %    Name:    paintPoly
  348. %    Syntax:    [x y] ... [x y] n rect paintPoly -
  349. %    Description:
  350. %        Given a polygon, this builds its path, and paints it with the pen pattern.
  351. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  352. d105 5
  353. a109 9
  354.  
  355. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  356. %    Opcode:    0072
  357. %    Name:    erasePoly
  358. %    Syntax:    [x y] ... [x y] n rect erasePoly -
  359. %    Description:
  360. %        Given a polygon, this builds its path, and fills it with the background
  361. %        pattern (thus 'erasing' it).
  362. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  363. d120 5
  364. a124 11
  365.  
  366. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  367. %    Opcode:    0073
  368. %    Name:    invertPoly
  369. %    Syntax:    [x y] ... [x y] n rect invertPoly -
  370. %    Description:
  371. %        Passed a polygon, this builds the path, and inverts it.  Well.  In theory
  372. %        only.  Actually, all this does is build the path so (a) we get the data off
  373. %        the stack, and (b) make it trivial for someone to add code here to make this
  374. %        work as advertised...
  375. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  376. d133 5
  377. a137 8
  378.  
  379. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  380. %    Opcode:    0074
  381. %    Name:    fillPoly
  382. %    Syntax:    [x y] ... [x y] n rect fillPoly -
  383. %    Description:
  384. %        Passed a polygon, this builds the path, and fills it
  385. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  386. d147 2
  387. a148 4
  388.  
  389. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  390. %    Opcode:    0078
  391. %    Name:    frameSamePoly
  392. d150 2
  393. a151 3
  394. %    Description:
  395. %        This is not presently implemented by Apple, and thus it also does nothing here
  396. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  397. d156 2
  398. a157 4
  399.  
  400. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  401. %    Opcode:    0079
  402. %    Name:    paintSamePoly
  403. d159 2
  404. a160 3
  405. %    Description:
  406. %        This is not presently implemented by Apple, and thus it also does nothing here
  407. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  408. d165 2
  409. a166 4
  410.  
  411. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  412. %    Opcode:    007A
  413. %    Name:    eraseSamePoly
  414. d168 2
  415. a169 3
  416. %    Description:
  417. %        This is not presently implemented by Apple, and thus it also does nothing here
  418. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  419. d174 2
  420. a175 4
  421.  
  422. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  423. %    Opcode:    007B
  424. %    Name:    invertSamePoly
  425. d177 2
  426. a178 3
  427. %    Description:
  428. %        This is not presently implemented by Apple, and thus it also does nothing here
  429. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  430. d183 2
  431. a184 4
  432.  
  433. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  434. %    Opcode:    007C
  435. %    Name:    fillSamePoly
  436. d186 2
  437. a187 3
  438. %    Description:
  439. %        This is not presently implemented by Apple, and thus it also does nothing here
  440. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  441. a190 1
  442.  
  443. @
  444.  
  445.  
  446. 1.3
  447. log
  448. @Thu Dec  3 18:02:10 PST 1992
  449. @
  450. text
  451. @d84 1
  452. @
  453.  
  454.  
  455. 1.2
  456. log
  457. @Fri Nov 27 19:38:16 PST 1992
  458. @
  459. text
  460. @@
  461.  
  462.  
  463. 1.1
  464. log
  465. @Sun Nov  8 09:29:02 PST 1992
  466. @
  467. text
  468. @d22 4
  469. a25 1
  470. %        This routine CHANGES THE CLIP PATH.  Beware of this.  Best to call this inside a gsave/grestore pair.
  471. d39 4
  472. a42 4
  473.         left top moveto
  474.         right 2 add top lineto
  475.         right 2 add bottom 2 add lineto
  476.         left bottom 2 add lineto
  477. d74 1
  478. @
  479.